<?php
/**
 * Created by PhpStorm.
 * User: Thans
 * Date: 2018/10/19
 * Time: 15:25
 */

namespace app\user\controller;


use app\common\controller\Base;
use app\user\facade\User;

class PublicController extends Base
{
    public function login()
    {
        \thans\log\controller\Log::setTitle('登录');
        if (!captcha_check($this->request->post('code'), 'login')) {
            return json([
                'code' => 4004,
                'msg' => '验证码错误',
                'data' => [],
            ]);
        }
        $data['user_login'] = $this->request->post('user_login');
        $data['user_pass'] = $this->request->post('user_pass');
        $result = $this->validate($data,
            'app\admin\validate\UserValidate.user_login');
        if (true !== $result) {
            return [
                'code' => 4003,
                'msg' => $result,
                'data' => [],
            ];
        }
        $data['user_type'] = [1, 2];
        $data['login_ip'] = $this->request->ip();
        return User::login($data);
    }
}